<template>
<div class="content profile">
  <header class="bar bar-nav">
    <!-- <a class="button button-link button-nav pull-left" v-link="{path: '/user', replace: true}">
    <span class="icon icon-left"></span>
    </a> -->
    <h1 class="title">登录错误</h1>
  </header>
  <!-- <div class="list-block">
    <ul style="margin-top:.5rem;">
      <li>
        <div class="item-content">
            <div class="item-inner">
                <div class="item-title label">用户名</div>
                <div class="item-input">
                    <input id="name" type="number" name="name" v-model="name" placeholder="用户名" value="">
                </div>
            </div>
        </div>
      </li>
      <li>
        <div class="item-content">
            <div class="item-inner">
                <div class="item-title label">密码</div>
                <div class="item-input">
                    <input id="pwd" type="password" v-model="pwd" name="pwd" placeholder="密码" value="">
                </div>
            </div>
        </div>
      </li>
    </ul>
  </div> -->
  <!-- <div class="submit-button"> -->
    <!-- <button @click="login()" class="button button-big button-fill">登录</button> -->
  <!-- </div>  -->
  <div class="content" style="text-align:center; font-size:2rem">
      <div class="content-block">{{content}}</div>
  </div>
</div>
</template>
<script>
import $ from 'zepto'
import _global from './global'
export default {
  data () {
    return {
      // oldPath: '',
      // name: '',
      // pwd: ''
      content: '',
      code: -999,
      id: 0
    }
  },
  ready () {
    this.content = ''
    this.getContent()
  },
  methods: {
    getContent () {
      if (this.$route.params.code) {
        this.code = parseInt(this.$route.params.code, 0)
        this.id = parseInt(this.$route.params.id, 0)
      }
      // if (this.code === 0) {
      //   window.localStorage.setItem('id', this.id)
      //   this.content = ''
        // this.$router.go('/home')
        // this.$router.push({ path: '/home' })
        // location.reload()
      // }
      if (this.code !== 0) {
        this.content = '未知错误,请重新登录'
      }
      if (this.code === 1000) {
        this.content = '只能使用微信浏览器登录'
      }
      if (this.code === -1) {
        this.content = '您尚未拥有代理资格，请联系推广人员'
      }
      if (this.code === -2) {
        this.content = '您尚未拥有代理资格，请联系推广人员'
      }
      if (this.code === -3) {
        this.content = '您尚未拥有代理资格，请联系推广人员'
      }
      if (this.code === -4) {
        this.content = '您已经绑定在其他用户下面，不能成为代理'
      }
      if (this.code === 2) {
        this.content = '服务器忙，请稍后再试'
      }
      console.log('code:', this.code, 'id:', this.id)
    },
    login () {
      let self = this
      window.localStorage.setItem('user_id', self.name)
      let re = /\D/g
      if (re.test(this.pwd)) {
        $.alert('密码只能输入数字')
        return
      }
      this.$http.get(_global.url + '/login?pwd=' + self.pwd + '&userId=' + self.name).then(function(res) {
        if (typeof res.data === 'string') {
          res.data = JSON.parse(res.data)
        }
        console.log(res.data)
        if (parseInt(res.data.errcode, 0) === 3) {
          $.alert('账号或密码错误')
          return
        }
        if (parseInt(res.data.errcode, 0) === 1) {
          $.alert('密码错误')
          return
        }
        if (parseInt(res.data.errcode, 0) === 4) {
          $.alert('您没有权限')
          return
        }
        if (parseInt(res.data.errcode, 0) === 0) {
          window.localStorage.setItem('user_id', res.data.data.user_id)
          window.localStorage.setItem('id', res.data.data.id)
          window.localStorage.setItem('role_id', res.data.data.role_id)
          self.$router.go('/home/')
          location.reload()
          return
        }
      }, function(res) {
        console.log(res)
      })
      // return '/home'
    }
  }

}
</script>

<style>
.profile .list-block {
  margin: 2.4rem 0 1rem 0;
  font-size: .65rem;
}
.profile .list-block .item-subtitle {
  font-size: .65rem;
}
.profile .list-block .item-input {
  margin-top: .06rem;
  margin-bottom: .06rem;
}
.profile .list-block input {
  font-size: .65rem;
}
.profile .list-block select {
  font-size: .65rem;
}
.profile .list-block textarea {
  font-size: .65rem;
}
.profile .list-block .item-title.label  {
  width: 30%;
}
.profile .submit-button {
  margin: 0 auto 2rem auto;
  width: 100%;
  padding: 0 .45rem;
}
.profile .submit-button button {
  background-color: #ed8e07;
  width: 100%;
  line-height: 2.1rem !important;
  height: 2.1rem !important;
}
.label{
  color: black
}
</style>
